﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using System.Data;

namespace APA_DAO
{
    public class KhachThueDao
    {
        public KhachThueDao()
        {
            new SqlHelper();
        }

        public DataTable getCustomerByInvoiceId(int id)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_KHACH_THUE_BY_STP", CommandType.StoredProcedure,
                "@SO_THUE_PHONG", id);
        }

        public DataTable getNonHostCustomerByInvoiceId(int id)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_KHACH_THUE_KHONG_LA_NGUOI_DAI_DIEN_BY_STP", CommandType.StoredProcedure,
                "@SO_THUE_PHONG", id);
        }

        public DataRow getCustomerById(int id)
        {
            DataTable table = SqlHelper.ExecuteDataTable("SP_GET_KHACH_THUE_INFOR_BY_ID", CommandType.StoredProcedure,
                "@ID", id);
            if (table != null)
            {
                return table.Rows[0];
            }
            return null;
        }

        public string insertKhachThue(string hoTen, DateTime ngaySinh, string gioiTinh, string soDT, string CMND, DateTime? ngayCap, string noiCap, string diaChi, string hinhAnh, int soThuePhong, int level)
        {
            return SqlHelper.getString("SP_INSERT_KHACH_THUE",
                "@HO_VA_TEN", hoTen,
                "@NGAY_SINH", ngaySinh,
                "@GIOI_TINH", gioiTinh,
                "@CMND", CMND,
                "@NGAY_CAP", ngayCap,
                "@NOI_CAP", noiCap,
                "@DIA_CHI", diaChi,
                "@SO_DT", soDT,
                "@SO_THUE_PHONG", soThuePhong,
                "@HINH_ANH", hinhAnh,
                "@LEVEL", level,              
                "@USR_ID", LoginDao.userID);
        }

        public bool updateKhachThue(int id, string hoTen, DateTime ngaySinh, string gioiTinh, string soDT, string CMND, DateTime? ngayCap, string noiCap, string diaChi, string hinhAnh)
        {
            return SqlHelper.ExecuteNonQuery("SP_UPDATE_KHACH_THUE", CommandType.StoredProcedure,
                "@ID", id,
                "@HO_VA_TEN", hoTen,
                "@NGAY_SINH", ngaySinh,
                "@GIOI_TINH", gioiTinh,
                "@SO_DT", soDT,
                "@CMND", CMND,
                "@NGAY_CAP", ngayCap,
                "@NOI_CAP", noiCap,
                "@DIA_CHI", diaChi,
                "@HINH_ANH", hinhAnh,
                "@USR_ID", LoginDao.userID);
        }

        public bool setNguoiDaiDien(int id, int invoiceId)
        {
            return SqlHelper.ExecuteNonQuery("SP_SET_NGUOI_DAI_DIEN_BY_ID", CommandType.StoredProcedure,
                "@ID", id,
                "@INVOICE_ID", invoiceId,
                "@USR_ID", LoginDao.userID);
        }

        public bool deleteKhachThue(int id)
        {
            return SqlHelper.ExecuteNonQuery("SP_DELETE_KHACH_THUE", CommandType.StoredProcedure,
                "@ID", id,
                "@USR_ID", LoginDao.userID);
        }
    }
}
